package com.lj.demo.statisticsService.utils;

import com.lj.demo.statisticsService.entity.StatisticsDaily;
import com.lj.demo.statisticsService.service.StatisticsDailyService;
import org.ehcache.core.spi.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: liujiang
 * @Date: 2021/01/18/21:13
 * @Description: 定时任务
 */
@Component
public class ScheduledTask {
    @Autowired
    private StatisticsDailyService dailyService;

    /**
     * 每天凌晨一点执行定时
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){
        //获取上一天的日期
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        dailyService.createStatisticByDate(day);
    }
}
